import sqlite3

dbFilename = r'BlockDb\BlockDb.db'
dbConn = sqlite3.connect(dbFilename)
print("Opened database successfully")

#创建表Block
strSql = "CREATE TABLE [Block](\
  [B_RecordID] INTEGER PRIMARY KEY AUTOINCREMENT DEFAULT 0, \
  [B_Filename] TEXT NOT NULL UNIQUE, \
  [B_BlockID] INT64 DEFAULT 0, \
  [B_BlockHash] TEXT, \
  [B_Timestamp] FLOAT DEFAULT 0, \
  [B_PrevBlockID] INT64 DEFAULT 0, \
  [B_PrevBlockHash] TEXT, \
  [B_Confirmed] INTEGER DEFAULT 0, \
  [B_Forked] INTEGER DEFAULT 0);"
c = dbConn.cursor()
c.execute(strSql)
dbConn.commit()
print("CREATE TABLE [Block] Successfully.")

#创建表MiningDifficulty
strSql = "CREATE TABLE [MiningDifficulty](\
  [MD_Phase] INT PRIMARY KEY, \
  [MD_MiningDifficulty] INT) WITHOUT ROWID;"
c = dbConn.cursor()
c.execute(strSql)
dbConn.commit()
print("CREATE TABLE [MiningDifficulty] Successfully.")


# dbConn.commit()
dbConn.close()
